package ServerStuff;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import DataStorageClasses.Employee;
import Database.DatabaseConnector;

@WebServlet("/AddEmployeeServlet")
public class AddEmployeeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		DatabaseConnector dbConnect = new DatabaseConnector();
		HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse res = (HttpServletResponse) response;
		HttpSession session = req.getSession();
		double wage = 0.0;
		long SIN = 0;
		
		String busName = (String) session.getAttribute("username");
		
		String first = request.getParameter("first");
		String last = request.getParameter("last");
		//String email = request.getParameter("email");
		String street = request.getParameter("street");
		String city = request.getParameter("city");
		String prov = request.getParameter("prov");
		String post = request.getParameter("post");
		String tel = request.getParameter("tel");
		String cell = request.getParameter("cell");
		//String start = request.getParameter("date");
		String w = request.getParameter("wage");
		String s = request.getParameter("sin");
		if(w != null && w != "")
		{
			wage = Double.parseDouble(w);
		}
		if(s != null && s != ""){
			SIN = Long.valueOf(s);
		}
		
		Employee e = dbConnect.addEmployee(busName, first, last, null, null, wage, SIN, street, city, prov, post, tel, cell);
				
		
		if( e != null)
    	{
    		//great!
    		System.out.println("add employee worked");
    		//session.setAttribute("login", true);
    		//session.setAttribute("busName", busName);
    		res.sendRedirect("/GoGoGadget/EmployeeList.jsp");
    	}
    	else
    	{
    		System.out.println("add employee didn't work");
    	}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
